package com.ckjava.xutils.service;

import org.quartz.CronExpression;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class CronService {

    @PostConstruct
    public List<Date> getNextFireDateList(String cronExpression, int times) throws Exception {
        Date now = new Date();
        List<Date> list = new ArrayList<>();

        CronExpression cron = new CronExpression(cronExpression);
        for (int i = 0; i < times; i++) {
            now = cron.getNextValidTimeAfter(now);
            list.add(now);
        }

        return list;
    }
}
